<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="statisticsDayOption"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
    >
      <template slot="menuLeft">
        <el-button
          type="primary"
          size="small"
          @click="exportExcel"
        >
          导出Excel
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import crudMixins from '@/mixins/crud.js';
import { getDairyOfDayStatistics } from '@/api/core/adopt';
import { statisticsDayOption } from '@/const/crud/pet/adoptDiary';
export default {
  mixins: [crudMixins],
  data() {
    return {
      statisticsDayOption: statisticsDayOption(),
    };
  },
  methods: {
    getList(page, refresh) {
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      getDairyOfDayStatistics(
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
          },
          this.searchForm
        )
      )
        .then((res) => {
          this.tableData = res.data.data.records;
          this.page.total = res.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    //  导出excel
    exportExcel() {
      this.downBlobFile(
        '/core/cloud/adopt/diary/statistics/day/export',
        this.searchForm,
        'diaryDay.xlsx'
      );
    },
  },
};
</script>
